nomainwin
WindowWidth=400:WindowHeight=400
open "Draw a Triangle" for graphics_nsb_nf as #1
#1 "trapclose [quit]"
#1 "down; fill cyan"
#1 "color red; size 5" 'will be used to outline figure
#1 "backcolor yellow" 'will be used to fill figure
#1 "setfocus;when leftButtonDown [draw]"
#1 "place 10 30"
#1 "\Click three spots to draw a triangle."
h=hwnd(#1) 'window handle
'get device context for window:
calldll #user32, "GetDC",_
h as long,_ 'window handle
hdc as long 'returns handle to device context
STRUCT PolyPoints,_
x1 as long,_
y1 as long,_
x2 as long,_
y2 as long,_
x3 as long,_
y3 as long
nCount=3 'number of x,y pairs in STRUCT
wait
[draw]
count=count+1
if count=1 then
'remove text
#1 "fill cyan"
'draw vertex
#1 "set ";MouseX;" ";MouseY
'fill first xy pair in struct with mouse coords
PolyPoints.x1.struct=MouseX
PolyPoints.y1.struct=MouseY
wait
end if
if count=2 then
'draw vertex
#1 "set ";MouseX;" ";MouseY
'fill second xy pair in struct with mouse coords
PolyPoints.x2.struct=MouseX
PolyPoints.y2.struct=MouseY
wait
end if
if count=3 then
'draw vertex
#1 "set ";MouseX;" ";MouseY
'fill struct with last point xy
PolyPoints.x3.struct=MouseX
PolyPoints.y3.struct=MouseY
count=0 'reset counter variable
end if
'after the third mouse click, draw the triangle
calldll #gdi32, "Polygon",_
hdc as long,_ 'device context of window or control
PolyPoints as struct,_'array of points
nCount as long,_ 'number of x,y pairs in array
result as boolean
'method to flush GDI graphics:
#1 "place 10 30"
#1 "\Click three spots to draw a triangle."
#1 "segment segID"
#1 "delsegment segID"
#1 "getbmp pix 0 0 400 400"
#1 "drawbmp pix 0 0;flush"
wait
[quit]
close #1
calldll #user32, "ReleaseDC",_
h as long,_ 'window handle
hdc as long,_ 'device context
ret as long
end